package com.team7.member.contorller;

import com.team7.common.utils.OSSUtil;
import com.team7.common.utils.SendMsg;
import com.team7.common.vo.CommonResult;
import com.team7.member.entity.Member;
import com.team7.member.service.MemberService;
import com.team7.member.vo.MemberVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName: MemberController
 * @Description: 会员表前端控制器
 * @Author: 赵孟阳
 * @Date: 2021/10/19 11:01
 */
@RestController
@RequestMapping("/student/member")
@Api(tags = "查询会员信息的API接口")
public class MemberController {


    @Autowired
    private MemberService memberService;


    @ApiOperation("通过手机号查询用户")
    @GetMapping("/findStudentBymobile/{mobile}")
    public Member findStudentBymobile(@PathVariable("mobile") String mobile) {
        System.out.println("123456++++++++++++++++++++++++++");
        return memberService.findStudentBymobile(mobile);
    }

    @ApiOperation("上传用户头像图片")
    @PostMapping("/uploadMsg")
    public String uploadMsg(MultipartFile file){
        return OSSUtil.getOssUrl(file);
    }

    @ApiOperation("通过退出用户登录")
    @GetMapping("/tuichuLogin")
    public CommonResult tuichuLoginMember() {
        return memberService.tuichuLoginMember();
    }

    @ApiOperation("通过会员id查询会员信息的接口")
    @GetMapping("/findStudentById/{id}")
    public CommonResult findStudentById(@PathVariable("id") String id) {
        return memberService.findStudentById(id);
    }

    @ApiOperation("查询会员信息的接口")
    @PostMapping("/getStudentAll/{page}/{limit}")
    public CommonResult getStudentAll(
            @PathVariable("page") Integer page,
            @PathVariable("limit") Integer limit,
            @RequestBody MemberVo studentVo
    ) {
        return memberService.getStudentAll(page, limit, studentVo);
    }

    @ApiOperation("添加用户信息")
    @PostMapping("/updateMemberPassword/{mobile}/{newPassword}")
    public CommonResult updateMemberPassword(@PathVariable("mobile") String mobile,@PathVariable("newPassword") String newPassword){
        return memberService.updateMemberPassword(mobile,newPassword);
    }


    @ApiOperation("修改会员信息")
    @PostMapping("/modifyStudentInformation")
    public CommonResult modifyStudentInformation(@RequestBody Member member){
        return memberService.modifyStudentInformation(member);
    }

    @ApiOperation("修改会员的状态")
    @PostMapping("/stateChange/{isDisabled}/{id}")
    public CommonResult stateChange(@PathVariable("isDisabled") Boolean isDisabled,@PathVariable("id") String id){
        return memberService.stateChange(isDisabled,id);
    }

    @ApiOperation("获得用户中教师和普通用户的人数")
    @GetMapping("/getMemberNum")
    public CommonResult getMemberNum(){
        return memberService.getMemberNum();
    }

    @ApiOperation("获取手机验证码")
    @GetMapping("/getYanZhengMa/{mobile}")
    public CommonResult getYanZhengMa(@PathVariable("mobile") String mobile){
        int dx = SendMsg.dx(mobile);
        return new CommonResult(2000,"获取成功",dx+"");
    }

    @ApiOperation("添加用户信息")
    @PostMapping("/installMember/{mobile}/{qianPassword}")
    public CommonResult installMember(@PathVariable("mobile") String mobile,@PathVariable("qianPassword") String qianPassword){
        return memberService.installMember(mobile,qianPassword);
    }
}
